package com.luli.controllor;

import lombok.extern.slf4j.Slf4j;
import org.influxdb.InfluxDB;
import org.influxdb.dto.BatchPoints;
import org.influxdb.dto.Point;
import org.influxdb.dto.Query;
import org.influxdb.dto.QueryResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.ArrayList;
import java.util.List;

/**
 * @Projectname: elasticsearch
 * @Filename: InfluxController
 * @Author: 陆离
 * @Data:2023/4/13 10:39:31
 */
@Slf4j
@RestController
@RequestMapping("/Influx")
public class InfluxController {
    @Autowired
    private InfluxDB influxDB;

    //measurement
    private final String measurement = "cpu_load_short";

    @Value("${spring.influx.database}")
    private String database;

    /**
     * 批量插入第一种方式
     * 127.0.0.1:8086/LuLi/Influx/indexTest
     */
    @GetMapping("/indexTest")
    public void insert(){
        QueryResult query = query("SELECT * FROM cpu_load_short");
        log.info("=====" + query);
    }

    /**
     * 查询
     *
     * @param command 查询语句
     * @return
     */
    public QueryResult query(String command) {
        return influxDB.query(new Query(command, measurement));
    }
}
